package com.ar.customview;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class SubjectImage extends ImageView {
	private JSONObject data;
	private String subjectId;
	private String subjectName;
	private String imageName;
	private Context mContext;

	public SubjectImage(Context context) {
		super(context);
		this.mContext = context;
	}

	public SubjectImage(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.mContext = context;
	}

	public SubjectImage(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.mContext = context;
	}

	public JSONObject getData() {
		return data;
	}

	public void setData(JSONObject data) {
		this.data = data;
		
		try {
			setSubjectId(data.getString("id"));
			setSubjectName(data.getString("name"));
			setImageName(data.getString("image"));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public String getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(String subjectId) {
		this.subjectId = subjectId;
	}

	public String getSubjectName() {
		return subjectName;
	}

	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}

	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		if(!(imageName.equals("")||imageName == null)) {
			this.imageName = imageName;
		this.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(imageName, "drawable", mContext.getPackageName())));
		}
	}
	

}
